<?php 
include 'include/init.php'; 
include $_SERVER['DOCUMENT_ROOT'].'/fr/include/require_login.php';
include $_SERVER['DOCUMENT_ROOT'].'/fr/include/fonctions.php';

function splitcar($car){
	$str = "";
	$arr = explode(".", $car);
	$str = implode("", $arr);
	$arr = explode(" ", $str);
	$str = implode("", $arr);
	return $str;
}

function random($car) {
	$string = "";
	$chaine = "abcdefghijklmnpqrstuvwxy".splitcar(microtime());
	srand((double)microtime()*1000000);
	for($i=0; $i<$car; $i++) {
		$string .= $chaine[rand()%strlen($chaine)];
	}
	return $string;
}

$uid = random(12);

if($_POST['submitquery']=="pay"){
	$_SESSION['com_pay'] = $pay_mode;
	if($_SESSION['com_pay']=='cheque'){
		header("location: /fr/paycheque.php" );
	} else {
		$_SESSION['com_ref'] = $_POST['order_ref'];
		$_SESSION['com_id'] = md5(uniqid(rand(), true));
		
		mysql_query("INSERT INTO `command` (
		`com_id`, `com_ref`, `user_id`, `com_price`, `com_statut`, `com_date`, `com_liv`, `com_pay`)
		VALUES ('".$_SESSION['com_id']."', '".$uid."', '".$_SESSION['user_id']."', '".$_SESSION['com_total']."', 'En cours de traitement', NOW(), '".$_SESSION['com_liv']."', '".$_SESSION['com_pay']."');");
		
		$q1 = mysql_query("SELECT * FROM `cart` WHERE com_id = '0' AND user_id = '".$_SESSION['user_id']."'");
		while ($r1 = mysql_fetch_array($q1) ){
			mysql_query("INSERT INTO `cart` (`cart_id`, `user_id`, `com_id`, `pro_id`, `pro_quantity`)
			VALUES ('".$_SESSION['com_id'].$r1['pro_id']."', '".$_SESSION['user_id']."', '".$_SESSION['com_id']."', '".$r1['pro_id']."', '".$r1['pro_quantity']."');");
		}
		@$Reference_12 = $uid;
		$Reference_Cde = urlencode(substr($Reference_12, 0, 12));
		@$Language_2   = $stub_order['language']."FR";   
		$Code_Langue   = urlencode(substr($Language_2 , 0, 2));
		$Code_Societe  = "alicebutt";
		$Montant       = $_SESSION['com_total'];
		$Devise        = "EUR";
		$Texte_Libre   = "";
		$Texte_Bouton  = "Paiement CB";
		echo "<html><head>";
		echo "<link rel='stylesheet' type='text/css'>.hideform input {display:none;}</style>";
		echo "</head><body>";
		include 'cic/CheckOutStub.php';
		echo "<div class='hideform'>".$Formulaire_Paiement."</div>";
		echo "<script>PaymentRequest.submit();</script>";
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="expires" content="-1">
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<? include $_SERVER['DOCUMENT_ROOT'].'/fr/include/meta.php'; ?>
	<meta name="description" content="Herbes de Chine : Validation du panier" />
	<title>Herbes de Chine : Validation du panier</title>
	<link href="/fr/css/common.css" rel="stylesheet" type="text/css" />
	<link href="/fr/css/inside.css" rel="stylesheet" type="text/css" />
	<script language="javascript" type="text/javascript" src="/fr/js/static.js"></script>
</head>
<body>
	<? include 'include/header.php'; ?>
    <div id="tools">
    	<table>
        	<tr>
            	<td id="chemin"><a href="/fr/index.php">Accueil</a> > <a href="/fr/monpanier.php">Mon panier</a> > Valider ma commande</td>
                <td id="search">
					<? include 'include/displaytoolbar.php'; ?>

				</td>
            </tr>
        </table>
    </div>
    <table class="widescreen">
		<tr class="top"><td colspan="2"></td></tr>
	    <tr class="middle"><td class="content">
	<!-- // Ma commande //-->
			<table>
				<tr>
					<td colspan="3"><h2>Ma Commande</h2></td>
				</tr>
				<?
				$query = "(SELECT cart.pro_id, pro_nom, pro_nom_cn, pro_quantity, pro_poids, pro_prix FROM cart, produit WHERE user_id = '".$_SESSION['user_id']."' AND produit.pro_id = cart.pro_id AND com_id = '0') UNION (SELECT cart.pro_id, rec_nom, '', pro_quantity, '', rec_prix FROM cart, recette WHERE user_id = '".$_SESSION['user_id']."' AND com_id = '0' AND recette.rec_id = cart.pro_id)";
				$q1 = mysql_query($query);
				while ($cart = mysql_fetch_array($q1) ){
				$price = format_price($cart['pro_prix']*$cart['pro_quantity']);
				$total += $price;
				?>
				<tr class="ligne">
				<?
				if($cart['pro_poids']!="") $contenance = " (".$cart['pro_poids']." gr)";
				else $contenance = "";
				?>
					<td colspan="2"><strong><? echo $cart['pro_quantity']; ?> x </strong><? echo $cart['pro_nom']; ?> <? echo $cart['pro_nom_cn'].$contenance; ?></a></td>
					<td>EUR <? echo $price ?> TTC</td>
				</tr>
				<? }
				$total += $_SESSION['fraisliv'];
				$_SESSION['com_total'] = $total;
				?>
				<tr>
					<td></td>
					<td colspan="2" class="bar"><img src="/img/common/lightgreybar.gif" alt="" /></td>
				</tr>
				<?
				$_SESSION['com_liv'] = ($_SESSION['modeliv']=="2") ? "Livraison recommandée" : "Livraison standard";
				?>
				<tr class="imp">
					<td width="50%"></td>
					<td width="25%" class="left"><? echo $_SESSION['com_liv'] ?></td>
					<td width="25%" class="right">EUR <? echo $_SESSION['fraisliv']; ?> TTC&nbsp;</td>
				</tr>
				<tr>
					<td></td>
					<td colspan="2" class="bar"><img src="/img/common/lightgreybar.gif" alt="" /></td>
				</tr>
				<tr class="imp">
					<td></td>
					<td class="left">Montant de la commande</td>
					<td id="total" class="price right">EUR <? echo $total ?> TTC&nbsp;</td>
				</tr>
				<tr>
					<td></td>
					<td colspan="2" class="bar"><img src="/img/common/lightgreybar.gif" alt="" /></td>
				</tr>
				<tr>
					<td></td>
					<td colspan="2" class="addcart aright"><a href="/fr/monpanier.php"><img src="/img/common/modifier_btn.gif" alt="Modifier" /></a></td>
				</tr>
				<tr><td colspan="6">&nbsp;</td></tr>
			</table>
			<!--<div class="info">
				<input id="check1" type="checkbox" /><label for="check1">Cochez cette case si vous désirez vous faire livrer à une autre adresse.</label><br />
			</div>-->
		</td></tr>
		<tr class="bottom"><td colspan="2"></td></tr>
	</table><br />
	<!-- // Mes Coordonnées //-->
	<table class="widescreen">
		<tr class="top"><td colspan="2"></td></tr>
		<tr class="middle"><td class="content">
		<div class="double">
			<table class="left">
				<tr>
					<td colspan="2"><h2>Mon adresse de facturation</h2></td>
				</tr>
				<tr class="ligne">
					<td width="20%"><strong>Adresse</strong></td>
					<td>
						<?
						echo $_SESSION['user_title']." ".$_SESSION['adr_lastname']." ".$_SESSION['adr_firstname']."<br/>";
						if($_SESSION['adr_company']){
							echo $_SESSION['adr_company']."<br/>";
						}
						echo $_SESSION['adr_address']."<br/>";
						echo $_SESSION['adr_zipcode']."<br/>";
						echo $_SESSION['adr_country']."<br/>";
						?>
					</td>
				</tr>
				<tr><td colspan="2">&nbsp;</td></tr>
				<tr class="ligne">
					<td><strong>Téléphone</strong></td>
					<td><? echo $_SESSION['adr_phone'] ?></td>
				</tr>
				<? if($_SESSION['adr_cellphone']!=""){ ?>
				<tr class="ligne">
					<td><strong>Portable</strong></td>
					<td><? echo $_SESSION['adr_cellphone'] ?></td>
				</tr>
				<? } ?>
				<tr><td colspan="6">&nbsp;</td></tr>
			</table>
			<table class="right">
				<tr>
					<td colspan="2"><h2>Mon adresse de livraison</h2></td>
				</tr>
				<tr class="ligne">
					<td width="20%"><strong>Adresse</strong></td>
					<td>
						<?
						echo $_SESSION['user_title']." ".$_SESSION['liv_lastname']." ".$_SESSION['liv_firstname']."<br/>";
						if($_SESSION['liv_company']){
							echo $_SESSION['liv_company']."<br/>";
						}
						echo $_SESSION['liv_address']."<br/>";
						echo $_SESSION['liv_zipcode']."<br/>";
						echo $_SESSION['liv_country']."<br/>";
						?>
					</td>
				</tr>
				<tr><td colspan="2">&nbsp;</td></tr>
				<tr class="ligne">
					<td><strong>Téléphone</strong></td>
					<td><? echo $_SESSION['adr_phone'] ?></td>
				</tr>
				<? if($_SESSION['adr_cellphone']!=""){ ?>
				<tr class="ligne">
					<td><strong>Portable</strong></td>
					<td><? echo $_SESSION['adr_cellphone'] ?></td>
				</tr>
				<? } ?>
				<tr><td colspan="6">&nbsp;</td></tr>
			</table>
			<table class="clear">
				<tr><td colspan="2">&nbsp;</td></tr>
				<tr>
					<td colspan="2" class="bar"><img src="/img/common/lightgreybar.gif" alt="" /></td>
				</tr>
				<tr>
					<td></td>
					<td colspan="2" class="addcart aright"><a href="/fr/moncompte/profil.php?cal=val"><img src="/img/common/modifier_btn.gif" alt="Modifier" /></a></td>
				</tr>
				<tr><td colspan="2">&nbsp;</td></tr>
			</table>
		</div>
		</td></tr>
		<tr class="bottom"><td colspan="2"></td></tr>
	</table><br />
	<!-- // Mode de paiement //-->
	<table class="widescreen">
		<tr class="top"><td colspan="2"></td></tr>
		<tr class="middle"><td class="content">
			<table>
				<form name="pay" action="?" method="POST">
				<tr>
					<td colspan="2"><h2>Mode de paiement</h2></td>
				</tr>
				<tr class="imp">
					<td width="20%"></td>
					<td><input type="radio" name="pay_mode" value="cheque" /> Payer par chèque</td>
				</tr>
				<tr><td colspan="2">&nbsp;</td></tr>
				<tr>
					<td></td>
					<td class="bar"><img src="/img/common/lightgreybar.gif" alt="" /></td>
				</tr>
				<tr class="imp">
					<td width="20%"></td>
					<td><input type="radio" name="pay_mode" value="carte" CHECKED /> Payer par Carte Bleue</span>&nbsp;&nbsp;&nbsp;&nbsp;<img src="/img/common/cic/cb_logo.gif" alt="CB - Visa - MasterCard" /><!--<br /><br />
					<span class="tooltip">
					Notre site de paiement en ligne est actuellement indisponible en raison des opérations de maintenance pendant la période des vacances. Nous vous prions de bien vouloir nous excuser pour la gêne occasionnée. 
La possibilité de nous régler par chèque reste maintenue sur notre site.
					</span>--></td>
				</tr>
				<tr><td colspan="2">&nbsp;</td></tr>
				<tr>
					<td></td>
					<td class="bar"><img src="/img/common/lightgreybar.gif" alt="" /></td>
				</tr>
				<tr>
					<td></td>
					<td class="addcart aright">
					
					<input type="hidden" name="order_ref" value="<? echo $uid ?>" />
					<input type="hidden" name="submitquery" value="pay" />
					<a href="#" onClick="pay.submit();return false;"><img src="/img/common/btn/paiement.gif" alt="Paiement" /></a>
					</td>
				</tr>
				<tr>
					<td width="20%"></td>
					<td>&nbsp;&nbsp;Le paiement est sécurisé par CIC Paiement (<a target="_blank" href="/fr/info/paiementetsecurite.php" target="_blank">En savoir plus</a>)</td>
				</tr>
				<tr><td colspan="2">&nbsp;</td></tr>
				<tr>
					<td width="20%"></td>
					<td><a target="_blank" href="http://www.paiementcic.com/acheter/index.htm"><img src="/img/common/cic/paiementcic_logo.gif" alt="Paiement CIC" /></a> <a target="_blank" href="http://www.mastercard.com/ca/personal/fr/mastercardsecurity/securecode.html"><img src="/img/common/cic/SecureCode_logo.gif" alt="MasterCard SecureCode" /></a> <a href="http://www.visaeurope.ch/fr/visa_au_quotidien/verified.jsp" target="_blank"><img src="/img/common/cic/VerifiedByVisa_logo.gif" alt="Verified By Visa" /></a></td>
				</tr>
				<tr><td colspan="6">&nbsp;</td></tr>
				</form>
			</table>
		</td></tr>
		<tr class="bottom"><td colspan="2"></td></tr>
	</table>
	<? include 'include/footer.php'; ?>
</body>
</html>
